1 00:00:00,230 --> 00:00:03,620 In the last video, we created a UI for our battle royale. 2 00:00:03,650 --> 00:00:05,210 Let's go ahead and take a look at it. 3 00:00:05,210 --> 00:00:06,230 Starter GUI. 4 00:00:06,590 --> 00:00:11,150 That screen gooey and then go to Battle Royale frame. 5 00:00:11,150 --> 00:00:12,710 We're going to make that visible. 6 00:00:13,460 --> 00:00:19,940 Check that we also need to make it so that if you hit the accept button, you're added to the queue 7 00:00:19,970 --> 00:00:21,200 that will be teleported. 8 00:00:21,200 --> 00:00:24,710 If you hit the decline, you're not added to the queue. 9 00:00:24,740 --> 00:00:30,440 If you accept and then change your mind and decline, you're going to be taken out of the queue. 10 00:00:30,470 --> 00:00:32,180 I thought that would be a good way of doing it. 11 00:00:32,180 --> 00:00:35,810 Let's bring up our battle royale. 12 00:00:35,840 --> 00:00:44,600 Look in our battle royale, look, let's add two variables for our accept and decline buttons. 13 00:00:44,600 --> 00:00:53,120 So I'll go down to the bottom of the declaration section, do a local accept button. 14 00:00:53,420 --> 00:01:01,850 We'll do a battle frame, dot accept button and do the same thing for your decline. 15 00:01:01,850 --> 00:01:04,490 So we have a decline button. 16 00:01:05,030 --> 00:01:10,430 Battle frame dot decline button. 17 00:01:10,430 --> 00:01:11,270 Nice. 18 00:01:11,270 --> 00:01:13,320 Now let's get that button. 19 00:01:13,320 --> 00:01:16,770 We're going to go down to the bottom of the script. 20 00:01:16,800 --> 00:01:27,150 We'll get our accept button dot activated colon connect function so nothing gets passed into that function. 21 00:01:27,180 --> 00:01:34,080 Let's make the button that we press have the have a thicker border so we know what is selected. 22 00:01:34,080 --> 00:01:37,920 So I'll say accept button on the buttons. 23 00:01:37,920 --> 00:01:45,960 We have this border size pixel, maybe make it like 5 or 6. 24 00:01:45,990 --> 00:01:47,310 Let's try five. 25 00:01:48,240 --> 00:01:51,330 And then don't forget we have our decline button. 26 00:01:51,330 --> 00:01:58,140 So let's make sure that border size pixel is small. 27 00:01:58,140 --> 00:02:07,680 We'll make it one, then we'll use our battle re the same remote event that opened up our our UI. 28 00:02:07,710 --> 00:02:10,980 We're going to send back a colon. 29 00:02:10,980 --> 00:02:13,880 We'll do a fire server. 30 00:02:13,880 --> 00:02:15,170 A true. 31 00:02:15,200 --> 00:02:18,410 So if we hit the accept, we're going to send back a true. 32 00:02:18,440 --> 00:02:23,420 We're going to do almost exactly the same for the decline. 33 00:02:23,420 --> 00:02:25,130 I just did a copy there. 34 00:02:25,910 --> 00:02:30,230 Paste and be very careful when you copy and paste. 35 00:02:30,260 --> 00:02:32,540 We're going to do a decline button. 36 00:02:33,350 --> 00:02:41,000 The accept button is going to have a thin pixel border and the decline is going to be thick to show 37 00:02:41,000 --> 00:02:42,500 which one you selected. 38 00:02:42,500 --> 00:02:44,780 Now here, do not miss this. 39 00:02:44,960 --> 00:02:47,630 It's going to be hard to troubleshoot because you won't get an error. 40 00:02:48,080 --> 00:02:50,090 You just get two, two accepts. 41 00:02:50,090 --> 00:02:53,360 So on your decline, make sure you have a false here. 42 00:02:54,380 --> 00:03:00,530 Now on the server side, we're not handling the events coming over from the client, but we're going 43 00:03:00,530 --> 00:03:01,550 to do that in a minute. 44 00:03:01,580 --> 00:03:04,190 Let's test to see what our buttons look like. 45 00:03:06,990 --> 00:03:07,890 There we go. 46 00:03:08,040 --> 00:03:10,970 And we should make this a little smaller, too. 47 00:03:10,980 --> 00:03:16,650 And we also need to remember to turn visible off and hit the tab button. 48 00:03:17,330 --> 00:03:17,960 There we go. 49 00:03:17,960 --> 00:03:18,380 That's the. 50 00:03:18,380 --> 00:03:20,390 Except I could see that pretty good. 51 00:03:20,420 --> 00:03:22,010 That's the decline. 52 00:03:22,790 --> 00:03:24,050 That's looking good. 53 00:03:24,170 --> 00:03:26,540 I think we're done with that script. 54 00:03:26,540 --> 00:03:28,460 Let's go ahead and turn this off. 55 00:03:29,090 --> 00:03:35,180 So in our battle royale, look, we have these two events here where we fire to the server. 56 00:03:35,210 --> 00:03:41,090 Our battle is firing to the server, either a true or false, depending on whether we should add them 57 00:03:41,090 --> 00:03:45,010 to the queue, not add them or remove them if they're in the queue. 58 00:03:45,020 --> 00:03:48,950 Let's go up to our workspace. 59 00:03:48,950 --> 00:03:53,060 Battle will initiate battle script. 60 00:03:53,630 --> 00:03:53,930 All right. 61 00:03:53,960 --> 00:03:55,810 Now we already have our battle ready. 62 00:03:55,850 --> 00:04:00,620 That's what brought up the UI and made the noise and everything else, the little sound. 63 00:04:00,920 --> 00:04:03,290 Let's go to the bottom of that script. 64 00:04:03,320 --> 00:04:07,940 We're going to add an event handler for client side events. 65 00:04:08,510 --> 00:04:17,850 I'll just do Battle Re dot on server event Connect it. 66 00:04:18,810 --> 00:04:21,000 I'm going to call this function. 67 00:04:21,000 --> 00:04:23,460 I haven't created it yet, so it'll be an error. 68 00:04:23,460 --> 00:04:27,030 But player response. 69 00:04:27,870 --> 00:04:28,090 All right. 70 00:04:28,140 --> 00:04:30,090 So there's an error because we haven't defined it. 71 00:04:30,090 --> 00:04:32,280 I'm going to copy it so I spell it right. 72 00:04:32,280 --> 00:04:39,720 Control C I'm going to move up a little bit, maybe above send players. 73 00:04:40,430 --> 00:04:43,160 Yeah, maybe I'll make this the top function. 74 00:04:43,640 --> 00:04:49,220 Let's say local function control V player response. 75 00:04:49,220 --> 00:04:52,010 And we're going to get a player because it came from a client event. 76 00:04:52,010 --> 00:04:55,580 So whoever pressed the button player comes automatically. 77 00:04:55,580 --> 00:04:58,730 We didn't have to send it and then we're going to get our response. 78 00:04:58,730 --> 00:05:06,710 That's a true or a false player response is going to add the player to the queue based on what the response 79 00:05:06,710 --> 00:05:07,160 is. 80 00:05:07,190 --> 00:05:12,080 We're going to need two helper functions, though, before we proceed. 81 00:05:12,200 --> 00:05:18,110 I'll do a local function and I'm going to check to see if the player is already in the queue. 82 00:05:18,140 --> 00:05:24,350 We don't want to have them in the queue More than once, I'm going to say has let me move my mouse player 83 00:05:24,650 --> 00:05:32,570 and this is going to check to see if the table I'll just call it tab has the player or I should just 84 00:05:32,570 --> 00:05:38,180 call that L for element if the element is a value in the table. 85 00:05:38,720 --> 00:05:39,130 All right. 86 00:05:39,140 --> 00:05:46,260 I'm going to do a for loop in here for I and V in pairs. 87 00:05:47,130 --> 00:05:57,690 We'll check for, we'll check all the elements in the table and do if V which is going to be a player 88 00:05:57,690 --> 00:06:03,150 in this case equals equals the player that got passed in. 89 00:06:03,810 --> 00:06:08,040 Then we're going to return a true right. 90 00:06:08,040 --> 00:06:09,780 The player was in the table. 91 00:06:09,780 --> 00:06:15,900 So this is going to be like one, two, three, four, five, and this is going to be the players. 92 00:06:15,900 --> 00:06:18,660 So we really don't need to have an I. 93 00:06:18,690 --> 00:06:20,970 We're not going to use the index. 94 00:06:20,970 --> 00:06:28,290 Sometimes it's good to do that and underscore will show people who are reading your code Oh they're 95 00:06:28,290 --> 00:06:30,420 not using the index variable. 96 00:06:30,450 --> 00:06:32,580 They're only using the value. 97 00:06:32,910 --> 00:06:36,600 Let's put a print statement in here too, so we could check our code. 98 00:06:36,600 --> 00:06:47,520 I'm going to say print has player found player equals and now we'll just print out the player name. 99 00:06:49,650 --> 00:06:55,830 If we get to the end of our table and we haven't returned a true, then we're going to know that player 100 00:06:55,830 --> 00:06:57,060 was not in the table. 101 00:06:57,060 --> 00:06:59,690 So we'll say return false. 102 00:06:59,700 --> 00:07:04,240 And if you don't have the return false, you'll return nil and lua. 103 00:07:04,240 --> 00:07:05,910 It treats nil as a false. 104 00:07:05,910 --> 00:07:09,120 So if you miss this line, you're not going to have a problem. 105 00:07:09,120 --> 00:07:11,400 I like to keep it there for completeness. 106 00:07:11,490 --> 00:07:20,190 Now we're going to have another function to remove players from the queue if they accept and then change 107 00:07:20,190 --> 00:07:21,630 their mind and decline. 108 00:07:21,660 --> 00:07:24,660 Let's do a local function. 109 00:07:25,230 --> 00:07:27,330 Remove player. 110 00:07:27,870 --> 00:07:29,310 I'll have a tab. 111 00:07:29,310 --> 00:07:33,180 That's the table that's going to be the player table or the player queue. 112 00:07:33,210 --> 00:07:36,030 We call that and then player. 113 00:07:36,060 --> 00:07:42,090 I'm not using global variables in here or script script global because I might want to move this to 114 00:07:42,090 --> 00:07:43,350 a module or script. 115 00:07:43,350 --> 00:07:47,730 So let's do a for we could do our I or we could do an underscore. 116 00:07:47,730 --> 00:07:53,640 We're not going to use the index V in pairs. 117 00:07:53,940 --> 00:07:56,130 We'll have our table again. 118 00:07:56,250 --> 00:08:07,230 Do if V equals equals player, then table dot remove. 119 00:08:08,180 --> 00:08:09,830 Pass in the table. 120 00:08:10,370 --> 00:08:11,210 Oh, you know what? 121 00:08:11,210 --> 00:08:17,950 We are going to need the eye because this one removes based on index. 122 00:08:17,960 --> 00:08:19,130 Boo. 123 00:08:19,370 --> 00:08:20,900 All right, so we need that eye. 124 00:08:20,930 --> 00:08:28,820 So for inv in Paris, we're checking on the v, but we're doing the removal based on the eye, the index. 125 00:08:28,820 --> 00:08:30,660 So maybe found them. 126 00:08:30,710 --> 00:08:35,090 Found that player in the third spot, yank them out based on three. 127 00:08:35,450 --> 00:08:39,530 Now we can go down to our player response and finish that. 128 00:08:39,530 --> 00:08:43,370 So the event came in fired off player response. 129 00:08:43,370 --> 00:08:45,440 We're going to get the player, we're going to get a response. 130 00:08:45,440 --> 00:08:46,850 It's either true or false. 131 00:08:47,090 --> 00:08:53,840 I'll do a IF player just to make sure the player is there and response. 132 00:08:53,840 --> 00:08:56,090 So they hit true, right? 133 00:08:56,090 --> 00:08:57,950 They hit the accept button. 134 00:08:58,130 --> 00:08:59,750 Let me move that up a little bit. 135 00:09:01,070 --> 00:09:19,550 If not, has player in our player queue put in the player, then table dot insert player queue and player 136 00:09:19,850 --> 00:09:23,600 and we'll put a print statement here too just to make sure we know what's happening. 137 00:09:23,600 --> 00:09:27,470 So player has joined. 138 00:09:27,500 --> 00:09:28,190 Did I spell join? 139 00:09:28,190 --> 00:09:28,400 Right. 140 00:09:28,400 --> 00:09:28,670 Yeah. 141 00:09:28,700 --> 00:09:33,080 Joined the queue and let's put the player name. 142 00:09:33,080 --> 00:09:36,740 So we'll say oh we can put the whole queue. 143 00:09:38,040 --> 00:09:39,030 Yeah. 144 00:09:39,030 --> 00:09:40,290 Let's do the old cute. 145 00:09:40,590 --> 00:09:42,420 Just so we see what's going on. 146 00:09:42,420 --> 00:09:47,460 We don't want to accidentally, like, miss players being removed or something. 147 00:09:48,740 --> 00:09:49,190 All right. 148 00:09:49,190 --> 00:09:54,680 So if the response was false, let's go to this end right here. 149 00:09:55,100 --> 00:09:57,020 And we're going to do an else. 150 00:09:57,960 --> 00:09:58,230 Right. 151 00:09:58,230 --> 00:09:59,340 So we can do an else. 152 00:09:59,340 --> 00:10:02,550 If I think an else is safe, though. 153 00:10:02,700 --> 00:10:06,660 We'll say remove player. 154 00:10:06,960 --> 00:10:08,610 We'll get our player queue. 155 00:10:10,860 --> 00:10:14,010 Take a look at the player and the player queue. 156 00:10:14,520 --> 00:10:24,120 And then just print player has been removed from the queue. 157 00:10:26,400 --> 00:10:29,020 And maybe we'll print the whole player queue. 158 00:10:29,040 --> 00:10:30,690 Now let's put the player in this one. 159 00:10:30,690 --> 00:10:38,460 If we're testing this on Roblox server, we may not be able to see the whole queue unless we mess around 160 00:10:38,460 --> 00:10:40,380 with the settings pretty severely. 161 00:10:41,640 --> 00:10:46,340 Let's scroll down to start registration. 162 00:10:46,350 --> 00:10:48,080 What do we have to change? 163 00:10:48,090 --> 00:10:49,740 Well, this is good. 164 00:10:49,740 --> 00:10:51,360 We play our sound. 165 00:10:51,390 --> 00:10:55,380 We're not going to worry about inserting players into the table. 166 00:10:55,380 --> 00:11:00,420 We have functions for that fire, all clients that's going to bring up their UI. 167 00:11:00,450 --> 00:11:04,080 We're going to wait this approximately the same amount of time. 168 00:11:04,080 --> 00:11:06,060 We're not really going to be able to see a difference. 169 00:11:06,060 --> 00:11:08,040 That's about 15 seconds. 170 00:11:10,110 --> 00:11:11,940 Let's go ahead. 171 00:11:13,570 --> 00:11:16,570 Whoops and send players. 172 00:11:17,460 --> 00:11:21,540 And then we'll say is initiated is false, we'll be able to reset the queue. 173 00:11:21,570 --> 00:11:24,000 Let's take a look at send players. 174 00:11:24,390 --> 00:11:25,540 Let's go on up here. 175 00:11:25,590 --> 00:11:27,060 Send players right here. 176 00:11:28,910 --> 00:11:29,180 All right. 177 00:11:29,180 --> 00:11:36,470 So when we go ahead and send players, let's make sure there's a sufficient number of players in the 178 00:11:36,470 --> 00:11:37,010 queue. 179 00:11:37,040 --> 00:11:39,510 I'm going to make the required players one. 180 00:11:39,530 --> 00:11:48,770 So I'll say if that's the number of players in the player queue is greater than or equal to, we're 181 00:11:48,770 --> 00:11:52,720 going to need a variable for required players. 182 00:11:52,730 --> 00:11:54,560 We don't have that yet. 183 00:11:54,650 --> 00:11:56,500 So it's going to give us an error. 184 00:11:56,510 --> 00:11:59,030 So if that happens. 185 00:12:01,030 --> 00:12:03,820 Let's go down here and finish our F. 186 00:12:05,010 --> 00:12:05,670 Its format. 187 00:12:05,670 --> 00:12:06,810 Our document. 188 00:12:06,840 --> 00:12:09,060 Let's grab this name. 189 00:12:09,090 --> 00:12:13,020 Go up to the top where we do our variable declaration. 190 00:12:14,020 --> 00:12:18,970 Perhaps after the sound we'll do a local required players. 191 00:12:19,000 --> 00:12:20,500 I'm just going to make it one. 192 00:12:20,500 --> 00:12:21,540 But you can make it three. 193 00:12:21,550 --> 00:12:22,680 You can make it five. 194 00:12:22,690 --> 00:12:28,570 Remember, we're going to have awards, but maybe if one player goes, they deserve the reward. 195 00:12:28,570 --> 00:12:33,040 Even if even if they're not fighting anybody, they they participated. 196 00:12:33,730 --> 00:12:33,970 All right. 197 00:12:33,970 --> 00:12:36,040 We'll go back down to the send players. 198 00:12:36,040 --> 00:12:38,620 We're checking our required players. 199 00:12:39,760 --> 00:12:44,110 I think I'll put a little print statement in here because we're going to we're going to have to check 200 00:12:44,140 --> 00:12:45,940 we're going to have to do some troubleshooting. 201 00:12:46,300 --> 00:12:47,560 I'm sure it's going to work out. 202 00:12:47,560 --> 00:12:54,850 But just in case, we'll say prepare to teleport and you can do a UI for that if you want. 203 00:12:55,900 --> 00:12:56,170 All right. 204 00:12:56,170 --> 00:12:57,610 We're going to get our code. 205 00:12:58,600 --> 00:13:03,520 We're going to teleport and we got our player queue. 206 00:13:04,660 --> 00:13:06,790 I think we're ready to test. 207 00:13:06,790 --> 00:13:09,970 Let's go ahead and save this off now. 208 00:13:09,970 --> 00:13:11,890 We're not going to have our weapons transferred over. 209 00:13:11,890 --> 00:13:13,120 We haven't done that yet. 210 00:13:13,120 --> 00:13:16,370 And we're not going to be able to get back even when we die. 211 00:13:16,370 --> 00:13:23,120 But let's go over to our website, check out our game to see if we can teleport to the other side. 212 00:13:24,280 --> 00:13:30,410 I'm at the Roblox website, logged in as Simtek Nitro one and I see my game right here. 213 00:13:30,430 --> 00:13:32,200 Let's go ahead and start that up. 214 00:13:32,200 --> 00:13:35,240 And I'm also going to get my alt in the game too. 215 00:13:35,260 --> 00:13:36,540 So I clicked on it. 216 00:13:36,550 --> 00:13:37,390 I'll hit the play. 217 00:13:37,390 --> 00:13:39,430 We're going to download our player. 218 00:13:41,860 --> 00:13:42,310 All right. 219 00:13:42,340 --> 00:13:45,040 20 minutes later, after all of my updates. 220 00:13:45,070 --> 00:13:51,760 Let's go ahead and hit this little cog up here in the corner to bring up our developer console. 221 00:13:51,760 --> 00:13:52,200 Where is it? 222 00:13:52,210 --> 00:13:55,480 Settings Developer console. 223 00:13:55,510 --> 00:13:57,280 Take a look at what's going on. 224 00:13:59,140 --> 00:14:00,460 I'll move that up here. 225 00:14:00,460 --> 00:14:02,080 Hit server side. 226 00:14:02,110 --> 00:14:03,940 We're getting some health notifications. 227 00:14:03,940 --> 00:14:05,950 This is my alt right here. 228 00:14:05,950 --> 00:14:09,220 I have the phone so that he could accept the battle. 229 00:14:10,570 --> 00:14:12,020 Let's bring up our battle. 230 00:14:12,040 --> 00:14:13,390 This is going to be in a way, isn't it? 231 00:14:13,600 --> 00:14:14,680 Let's bring it down here. 232 00:14:15,070 --> 00:14:16,300 Hit the battle. 233 00:14:16,720 --> 00:14:17,830 Ding. 234 00:14:18,070 --> 00:14:19,300 I'm going to accept. 235 00:14:20,170 --> 00:14:21,040 I'm going to get my alt. 236 00:14:21,070 --> 00:14:22,270 He's going to accept. 237 00:14:23,400 --> 00:14:24,360 And. 238 00:14:24,360 --> 00:14:26,730 Oh, yeah, look, the player has joined the queue. 239 00:14:26,760 --> 00:14:30,750 We have to change our settings in order to actually see the whole table. 240 00:14:30,870 --> 00:14:31,430 That's all right. 241 00:14:31,440 --> 00:14:33,660 We got two notifications. 242 00:14:33,660 --> 00:14:35,820 Let's see if we teleport. 243 00:14:39,150 --> 00:14:39,810 Look at that. 244 00:14:39,810 --> 00:14:41,730 We're both in the world. 245 00:14:41,730 --> 00:14:46,090 So we teleported a group to our private server. 246 00:14:46,110 --> 00:14:51,780 Now, if somebody or even me, if I was to join the leave and join the game and come back, I could 247 00:14:51,780 --> 00:14:54,180 not get to this because this is a private server. 248 00:14:54,180 --> 00:14:56,910 You need the code, a reserved server. 249 00:14:56,910 --> 00:14:59,220 So that's pretty cool. 250 00:14:59,220 --> 00:15:05,970 Now all we have to do is create the logic on this end to send the people back when they die. 251 00:15:06,000 --> 00:15:08,700 Last person standing gets the reward. 252 00:15:08,700 --> 00:15:09,400 We're going to set up. 253 00:15:09,480 --> 00:15:10,530 Set up a little banner. 254 00:15:10,530 --> 00:15:10,980 Yay! 255 00:15:11,010 --> 00:15:11,520 You win. 256 00:15:11,520 --> 00:15:12,750 Maybe give him a prize. 257 00:15:13,170 --> 00:15:15,390 We also have to. 258 00:15:16,280 --> 00:15:18,660 Figure out how to bring our weapons, right? 259 00:15:18,680 --> 00:15:23,390 We have no weapons and we don't have any punching or anything either, so we can't even bruise them 260 00:15:23,390 --> 00:15:24,170 to death. 261 00:15:24,260 --> 00:15:25,910 That's pretty cool, though. 262 00:15:25,940 --> 00:15:27,620 I will see you in the next video. 263 00:15:27,620 --> 00:15:30,560 We will continue on our battle royale.